﻿using Assets.Script.Human.Player;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace Assets.Script.HelpSystem.AtkSystem.AtkObj
{
    public class Healing:MonoBehaviour
    {
        float haveTime;
        float time_interval;
        float health_per;

        float time=0;
        bool isHeal = false;



    public void Init(float haveTime, float time_interval, float health_per)
    {
        this.haveTime = haveTime;
        this.time_interval = time_interval;
        this.health_per = health_per;
        Destroy(gameObject, haveTime);
    }

    private void Update()
        {
            time += Time.deltaTime;
            if (isHeal)
            {
                isHeal = false;
            }

            if (time>=health_per)
            {
                isHeal = true;
                time = 0;
            }
        }

        private void OnTriggerStay(Collider other)
        {
            if (isHeal)
            {
                if (other.tag=="Player")
                {
                    other.GetComponent<PlayerBody>().GetHeal(health_per);
                }
            }
        }
    }
}
